package user_lazy_save_service

import (
	"fmt"
	"sen-golang-study/go_game_study/hero_story_go_server/biz_server/service/user/userdao"
	"sen-golang-study/go_game_study/hero_story_go_server/biz_server/service/user/userdata"
	"sen-golang-study/go_game_study/hero_story_go_server/common/async_op"
)

// UserLazySaver UML类图：https://www.processon.com/diagraming/686dd0a78800b52cd4f74a23
type UserLazySaver struct {
	*userdata.User
}

func (saver *UserLazySaver) GetId() string {
	return fmt.Sprintf("UserLazySaver_%d", saver.UserId)
}

func (saver *UserLazySaver) SaveOrUpdate() {
	// 通过异步方式保存数据
	async_op.Process(
		async_op.StrToBindId(saver.User.UserName),
		func() {
			userdao.SaveOrUpdate(saver.User)
		},
		nil,
	)
}
